#include "s401model.h"
#include <QDebug>

S401Model::S401Model(QObject *parent)
    : QAbstractListModel(parent)
{
    Data da{"string1","st1",true};
    Data da1{"string2","st2",true};
    Data da2{"string3","st3",true};
    Data da3{"string4","st4",true};
    dataList_.append(da);
    dataList_.append(da1);
    dataList_.append(da2);
    dataList_.append(da3);
}


int S401Model::rowCount(const QModelIndex &parent) const
{
//    if (!parent.isValid())
//        return 0;

    // FIXME: Implement me!
    qDebug()<<"dataList_.size() = " <<dataList_.size();
    return dataList_.size();
}


QVariant S401Model::data(const QModelIndex &index, int role) const
{
    qDebug()<<"dataList_.data() = " <<index<<role;
    if (!index.isValid())
        return QVariant();

    // FIXME: Implement me!
    int row = index.row();
     if(row < 0 || row >= dataList_.count()) {
         return QVariant();
     }

     const Data &data = dataList_[row];
     switch (role) {
     case TitleRole:
         return data.title_;
     case ContentRole:
         return data.content_;
     case SelectRole:
         return data.select_;
     default:
         return QVariant();
     }

    return QVariant();
}

QHash<int, QByteArray> S401Model::roleNames() const
{
    QHash<int, QByteArray> roles;
    roles[TitleRole] = "title_";
    roles[ContentRole] = "content_";
    roles[SelectRole] = "select_";
    return roles;
}
